﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "GbmpModel.h"
#include "IParameterOverride.h"
#include "IParameterValidator.h"
#include "NdbObjectSchematic.h"
#include "DbDataSchema.h"
#include "UniIdentity.h"

namespace gcmp
{
    class IModelView;
    class IElement;

    class ModelViewParameterValidator : public NdbObjectSchematic, public IParameterValidator
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, ModelViewParameterValidator, gcmp::NdbObjectSchematic, 1DC65F73 - D688 - 4326 - A7A7 - 76933659C2CA, gbmpmodel, gcmp::IParameterValidator)
        DBOBJECT_DATA_END

    public:
        virtual OwnerPtr<IParameterValidator> Clone() const override;
        virtual bool Validate(const IParameter* pNewParameter, const IElement* pElement, std::wstring* pErrorMessage = nullptr) const override;

    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override
        {
            return nullptr;
        }

    private:
        bool ValidateName(const IModelView* pModelView, const std::wstring& newName, std::wstring* pErrorMessage) const;
    };

    class ModelViewParameterValidatorOverride : public NdbObjectSchematic, public IParameterOverride
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, ModelViewParameterValidatorOverride, gcmp::NdbObjectSchematic, 973F0CF9 - 10AF - 4923 - 9F98 - 3CC4B4FC6F46, gbmpmodel, gcmp::IParameterOverride)
            DATA(UniIdentity, ParameterUid)
        DBOBJECT_DATA_END

    public:
        ModelViewParameterValidatorOverride(UniIdentity parameterUid);
        virtual UniIdentity GetUniIdentity() const override;

        virtual bool ShouldOverrideIsModifiable() const override;
        virtual bool IsModifiable() const override;

        virtual bool ShouldOverrideIsUserVisible() const override;
        virtual bool IsUserVisible() const override;

        virtual bool ShouldOverrideGetName() const override;
        virtual std::wstring GetName() const override;

        virtual bool ShouldOverrideGetValidator() const override;
        virtual const IParameterValidator* GetValidator() const override;

        virtual IElement* GetOwnerElement() override { return nullptr; }
        virtual const IElement* GetOwnerElement() const override { return nullptr; }
        virtual bool SetOwnerElement(IElement* pElement) override { return true; }

    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override
        {
            return nullptr;
        }
    };

    class ModelViewDisableTopPlaneOffsetValidatorOverride : public NdbObjectSchematic, public IParameterOverride
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, ModelViewDisableTopPlaneOffsetValidatorOverride, gcmp::NdbObjectSchematic, 1EA0E21C - 6DD7 - 4189 - AE42 - F4828BD5C36A, gbmpmodel, gcmp::IParameterOverride)
            DATA(UniIdentity, ParameterUid)
        DBOBJECT_DATA_END

    public:
        ModelViewDisableTopPlaneOffsetValidatorOverride(UniIdentity parameterUid);
        virtual UniIdentity GetUniIdentity() const override;

        virtual bool ShouldOverrideIsModifiable() const override;
        virtual bool IsModifiable() const override;

        virtual bool ShouldOverrideIsUserVisible() const override;
        virtual bool IsUserVisible() const override;

        virtual bool ShouldOverrideGetName() const override;
        virtual std::wstring GetName() const override;

        virtual bool ShouldOverrideGetValidator() const override;
        virtual const IParameterValidator* GetValidator() const override;

        virtual IElement* GetOwnerElement() override { return nullptr; }
        virtual const IElement* GetOwnerElement() const override { return nullptr; }
        virtual bool SetOwnerElement(IElement* pElement) override { return true; }

    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override
        {
            return nullptr;
        }
    };
}
